package com.yang.designmode.ActionMode.state.mario.table;

// 状态机
public class MarioStateMachine {
    private int score;

    private State currentState;

    public MarioStateMachine() {
        this.score = 100;
        this.currentState = State.SMALL;
    }

    //定义状态和积分的二维数组
    private static final State[][] transitionTable = {
            {State.SUPER, State.CAPE, State.FIRE, State.SMALL},
            {State.SUPER, State.CAPE, State.FIRE, State.SMALL},
            {State.CAPE, State.CAPE, State.CAPE, State.SMALL},
            {State.FIRE, State.FIRE, State.FIRE, State.SMALL},
    };

    private static final int[][] actionTable = {
            {100, 200, 300, 0},
            {0, 200, 300, -100},
            {0, 0, 0, -200},
            {0, 0, 0, -300},
    };

    public void obtainMushRoom(){
        executeEvent(Event.OBTAIN_MUSHROOM);
    }
    public void obtainCape(){
        executeEvent(Event.OBTAIN_CAPE);
    }
    public void obtainFire(){
        executeEvent(Event.OBTAIN_FIRE);
    }
    public void meetMonster(){
        executeEvent(Event.MEET_MONSTER);
    }

    public int getScore() {
        return score;
    }

    public State getCurrentState() {
        return currentState;
    }

    public void executeEvent(Event event) {
        int stateValue = currentState.getValue();
        int eventValue = event.getValue();
        this.currentState = transitionTable[stateValue][eventValue];
        this.score += actionTable[stateValue][eventValue];
    }
}